"""
Copyright 2012 Wieser Dietmar, Margit Mutschlechner.

This file is part of Multimedia Social Networking Platform.

Multimedia Social Networking Platform is free software: 
you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

Multimedia Social Networking Platform is distributed
in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with Multimedia Social Networking Platform.  
If not, see <http://www.gnu.org/licenses/>.

"""

import unittest
from msnp.persistence import PersistenceController
from msnp.model.MediaModel import NetSynchChanges, Media, MediaType
import time
from msnp.model import MediaModel
from msnp.logger import Logger

class TestNetSynchChangesAccessor(unittest.TestCase):
    
    def test(self):
        Logger.setLogToFile(False)
        PersistenceController.initMediaDatabase("localhost", "root", "root", "media_db_test")
        self.__testGetLastNetSynchId()
#        self.__testInsertNetSynchChanges()
#        self.__testSelectNetSynchChanges()
    
    def __testInsertNetSynchChanges(self):
        m = Media(None, MediaType.AUDIO, "testmedia", "2011", "testcomposer", None, None, 10, 1000, None)
        media_id = PersistenceController.insertMedia(m)
        timestamp = "%f" % time.time()
        netSynchChange = NetSynchChanges(media_id, "groupname", "ownername", "username", timestamp, True, MediaModel.NetSynchChangeSource.NETWORK)
        successful = PersistenceController.insertNetSynchChange(netSynchChange)
        self.assertEqual(True, successful)
        
        timestamp = "%f" % time.time()
        netSynchChange = NetSynchChanges(media_id, "groupname2", "ownername2", "username2", timestamp, True, MediaModel.NetSynchChangeSource.NETWORK)
        successful = PersistenceController.insertNetSynchChange(netSynchChange)
        self.assertEqual(True, successful)
    
    def __testGetLastNetSynchId(self):
        id = PersistenceController.selectLastNetSynchId()
        self.assertEqual(41, id)
        
            
#    def __testSelectNetSynchChanges(self):
#        netSynchChanges = PersistenceController.selectNetSynchChanges()
#        self.assertEqual(len(netSynchChanges), 2)
#        timestamp = "%f" % time.time()
#        netSynchChanges = PersistenceController.selectNetSynchChanges(timestamp)
#        self.assertEqual(len(netSynchChanges), 0)
        
    
def suite():
    suite = unittest.TestSuite()
    suite.addTest(unittest.makeSuite(TestNetSynchChangesAccessor))
    return suite

if __name__ == '__main__':
    suiteFew = unittest.TestSuite()
    unittest.TextTestRunner(verbosity=2).run(suite())
